home *** CD-ROM | disk | FTP | other *** search
/ FM Towns: Free Software Collection 8 / FM Towns Free Software Collection 8.iso / t_os / gpen32k / source / lib / osrc / fsel.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-06-01  |  5.4 KB  |  287 lines

  1. /*
  2.         Free File Selector V0.03
  3.                                 Copyright(C)1993 Okome
  4. */
  5.  
  6. #include    <stdio.h>
  7. #include    <string.h>
  8. #include    <ctype.h>
  9. #include    <direct.h>
  10. #include    <dos.h>
  11. #include    <EGB.H>
  12. #include    <MOS.H>
  13. #include    <FMCfrb.h>
  14. #include    <normlib.h>
  15. #include    <okome.h>
  16.  
  17. /*    サイズ    */
  18. #define    FX3    330
  19. #define    FY3    200
  20. #define    FX2    (Fx1+FX3)
  21. #define    FY2    (Fy1+FY3)
  22. #define    kx    (Fx1+16)
  23. #define    ky    (FY2-24)
  24. #define    xe    (FX3-20)
  25.  
  26. extern char work[];
  27.  
  28. void cccp( int x1, int y1, int x2, int y2, int x3, int y3, int sx, int sy )
  29. {
  30.     int y, ya, yb, yz;
  31.     char w0[1024], w1[1024];
  32.     if (y1<y2)
  33.     {
  34.         ya=sy;
  35.         yb=-1;
  36.         yz=-1;
  37.     }    else    {
  38.         ya=0;
  39.         yb=sy+1;
  40.         yz=1;
  41.     }
  42.     for (y=ya; y!=yb; y+=yz)
  43.     {
  44.         egbget( x3, y3+y, x3+sx, y3+y, w0 );
  45.         egbget( x1, y1+y, x1+sx, y1+y, w1 );
  46.         egbput( x1, y1+y, x1+sx, y1+y, w0 );
  47.         egbget( x2, y2+y, x2+sx, y2+y, w0 );
  48.         egbput( x2, y2+y, x2+sx, y2+y, w1 );
  49.         egbput( x3, y3+y, x3+sx, y3+y, w0 );
  50.     }
  51. }
  52.  
  53. static int Fx1=140, Fy1=70;
  54. static unsigned int edr;
  55. static struct _diskfree_t fre;
  56.  
  57. void wido( int *x, int *y, int sx, int sy )
  58. {
  59.     int mb, mx, my, mx2, my2;
  60.     MOS_rdpos( &mb, &mx, &my );
  61.     if (mx>=*x && my>=*y && mx<=*x+sx && my <= *y+sy )
  62.     {
  63.         mbout( &mb, &mx2, &my2 );
  64.         MOS_disp(0);
  65.         cccp( *x,*y, *x-mx+mx2,*y-my+my2, 640,0, sx,sy );
  66.         MOS_disp(1);
  67.         *x = *x-mx+mx2;
  68.         *y = *y-my+my2;
  69.     }
  70. }
  71.  
  72. static void fvr( int l, int c, struct _find_t fls[] )
  73. {
  74.     int i, x, y;
  75.     i = l*3;
  76.     boxbf( Fx1+6, Fy1+24, Fx1+xe, FY2-26, 15, 8 );
  77.     for ( y=0; (y+1) * 18 <= 152; y++ )
  78.     {
  79.         for ( x=0; (x+1) * 100 < xe; x++ )
  80.         {
  81.             if ( i < c )
  82.             {
  83.                 if ( fls[i].attrib & _A_SUBDIR )
  84.                 {
  85.                     EGB_color( work, 0, 14 );
  86.                 }    else    {
  87.                     EGB_color( work, 0, 15 );
  88.                 }
  89.                 print( Fx1+8+x*100, Fy1+40+y*18, fls[i++].name );
  90.             }    else    {
  91.                 fls[i++].name[0] = 0;
  92.             }
  93.         }
  94.     }
  95. }
  96.  
  97. static int fdir( struct _find_t fls[] )        /*    ファイル格納    */
  98. {
  99.     int c=0;
  100.     char drn[128];
  101.     struct _find_t fl;
  102.  
  103.     /*    ディレクトリ確定    */
  104.     _getcwd( drn, 124 );
  105.     if ( drn[3]==0 )
  106.     {
  107.         drn[2] = 0;
  108.     }
  109.     strcat( drn, "\\*.*" );
  110.     /*    ファイル情報    */
  111.     if ( _dos_findfirst( drn, _A_NORMAL | _A_SUBDIR, &fl ) == 0 )
  112.     {
  113.         fls[c++] = fl;
  114.         while ( _dos_findnext(&fl) == 0 )
  115.         {
  116.             fls[c++] = fl;
  117.         }
  118.         fvr( 0, c, fls );    /*    ファイル名表示    */
  119.     }
  120.     return (c);
  121. }
  122.  
  123. /*    HEat    file_select("mac",msg,drv,dir,wild,sort)    */
  124. /*
  125.     file_select("FILE","編集ファイル",-1, "", "*.*",-1)
  126.     if ( FILE = "" )
  127.     {    FILE = "dummy.mml"
  128.     }
  129. */
  130. int fsel( char *fna, char *msg, char dr )
  131. {
  132.     int i, x, y, mb, mx, my, c, d, p, rp=1, t=1, l=0;
  133.     unsigned int drv;
  134.     struct _find_t fls[256];
  135.     char w[1024];
  136.  
  137.     p = EGB_getWritePage( 0, 0 );
  138.     EGB_writePage( work, 0 );
  139.     MOS_disp(0);
  140.     for (y=Fy1; y<=FY2; y++)
  141.     {
  142.         egbget( Fx1, y, FX2, y, w );
  143.         egbput( 640,y-Fy1, 640+FX3,y-Fy1, w );
  144.     }
  145.  
  146.     /*    ドライブ設定    */
  147.     if (isalpha(dr))
  148.         dr = tolower(dr) - 'a';
  149.     dr++;
  150.     if (dr == 0)
  151.     {
  152.         _dos_getdrive( &edr );
  153.         dr = edr;
  154.     }
  155.     _dos_setdrive( dr, &edr );
  156.     drv = dr;
  157.  
  158.     /*    ドライブ情報    */
  159.     _dos_getdiskfree( drv, &fre );
  160.  
  161.     /*    画面原型    */
  162.     boxbf( Fx1,Fy1, FX2,FY2, 8, 6 );
  163.     boxf( Fx1+1, Fy1+1, Fx1+16+strlen(msg)*8, Fy1+18, 8 );
  164.     boxbf( FX2-16, Fy1+32, FX2-2, FY2-26, 15, 7 );
  165.     boxbf( kx, ky, kx+104, ky+20, 15, 8 );
  166.     boxb( FX2-100, Fy1+18, FX2-20, Fy1, 15 );
  167.     boxb( FX2-80, Fy1+18, FX2-40, Fy1, 15 );
  168.     EGB_color( work, 0, 15 );
  169.     EGB_fontStyle( work, 0 );
  170.     print( Fx1+7,Fy1+17, msg );
  171.     print( Fx1+18, FY2-6, fna );
  172.     w[0]=drv+'A'-1;
  173.     w[1]=0;
  174.     symbol(FX2-80,Fy1+17,w,16,15);
  175.  
  176.     c = fdir(fls);
  177.     /*    マウス処理    */
  178.     MOS_disp(1);
  179.     do
  180.     {
  181.         do
  182.         {
  183.             MOS_rdpos( &mb, &x, &y );
  184.             switch(keyin(Fx1+18, FY2-21, fna, 12, 15, 8, t ))
  185.             {
  186.             case 0:
  187.                 mb=3;
  188.                 rp=0;
  189.                 break;
  190.             case 2:
  191.                 mb=3;
  192.                 break;
  193.             default:
  194.                 break;
  195.             }
  196.             t = 0;
  197.         }    while( mb == 0 );
  198.         d = 0;
  199.         x -= Fx1;
  200.         y -= Fy1;
  201.         if (x>=8 && y>=23 && x<=xe+8 && y<=FY3-26)
  202.         {
  203.             d++;
  204.             i = (x-8)/100+((y-23)/18+l)*3;
  205.             if (fls[i].attrib & _A_SUBDIR)
  206.             {
  207.                 _chdir(fls[i].name);
  208.                 MOS_disp(0);
  209.                 c = fdir(fls);
  210.                 l = 0;
  211.                 MOS_disp(1);
  212.                 mbout( &mb, &x, &y );
  213.             }    else    {
  214.                 if ( strcmp( fna, fls[i].name )!=0 )
  215.                 {
  216.                     strcpy( fna, fls[i].name );
  217.                     t = 1;
  218.                 }
  219.             }
  220.         }
  221.         if ( x > FX3-100 && y < 18 && x<FX3-80 && y>0)
  222.         {
  223.             d++;
  224.             MOS_disp(0);
  225.             boxf(FX2-80,Fy1+1,FX2-70,Fy1+17,0);
  226.             if (drv>1)
  227.             {
  228.                 drv--;
  229.             }    else    {
  230.                 drv = edr;
  231.             }
  232.             w[0]=drv+'A'-1;
  233.             w[1]=0;
  234.             symbol(FX2-80,Fy1+17,w,16,15);
  235.             MOS_disp(1);
  236.             mbout( &mb, &mx, &my );
  237.         }
  238.         if ( x > FX3-40 && y < 18 && x<FX3-20 && y>0)
  239.         {
  240.             d++;
  241.             MOS_disp(0);
  242.             boxf(FX2-80,Fy1+1,FX2-70,Fy1+17,0);
  243.             if (drv<edr)    drv++;
  244.             w[0]=drv+'A'-1;
  245.             w[1]=0;
  246.             symbol(FX2-80,Fy1+17,w,16,15);
  247.             MOS_disp(1);
  248.             mbout( &mb, &mx, &my );
  249.         }
  250.         if ( x > FX3-80 && y < 18 && x<FX3-40 && y>0)
  251.         {
  252.             d++;
  253.             MOS_disp(0);
  254.             _dos_setdrive( drv, &edr );
  255.             _dos_getdiskfree( drv, &fre );
  256.             c = fdir(fls);
  257.             l= 0;
  258.             MOS_disp(1);
  259.             mbout( &mb, &mx, &my );
  260.         }
  261.         if ( 16 < x && FY3-24 < y && 16+104 > x && FY3-4 > y )
  262.         {
  263.             d++;
  264.             rp = 0;
  265.             mb = 3;
  266.         }
  267.         if ( x>=FX3-16 && x<=FX3-2 && y>=32 && y<=FY3-26 && l<c/3)
  268.         {
  269.             d++;
  270.             fvr( ++l, c, fls );
  271.         }
  272.         if ( d == 0)
  273.         {
  274.             wido( &Fx1, &Fy1, FX3, FY3 );
  275.         }
  276.     }    while( mb != 3 );
  277.     MOS_disp(0);
  278.     for (y=Fy1; y<=FY2; y++)
  279.     {
  280.         egbget( 640,y-Fy1, 640+FX3,y-Fy1, w );
  281.         egbput( Fx1, y, FX2, y, w );
  282.     }
  283.     MOS_disp(1);
  284.     EGB_writePage( work, p );
  285.     return (rp);
  286. }
  287.